<?php
declare (strict_types = 1);

namespace app\admin\controller;

use app\common\facade\Builder;
use think\facade\View;
//该文件为自动生成，请按需修改
class ProductFull extends Base
{
    //所有定义变量均为演示，请根据实际需求更改

    //主键，默认为id
    protected string $pk = 'id';

    //主模型
    protected string $model = '\app\common\model\ProductFull';
    protected string $productModel = '\app\common\model\Product';


    public function index(): string
    {
        //构建表格数据
        return Builder::Table()
            ->addColumn(['type' => 'checkbox', 'title' => '全选', 'fixed' => 'left'])
            ->addColumn(['field' => 'id', 'sort' => true, 'title' => 'ID', 'width' => 80])
            ->addColumn(['field' => 'title', 'title' => '标题', 'modify' => '2,input'])
            ->addColumn(['field' => 'money', 'title' => '金额', 'modify' => '2,input'])
            ->addColumn(['field' => 'sale_money', 'title' => '优惠金额', 'modify' => '2,input'])
            ->addColumn(['field' => 'sort', 'title' => '排序', 'modify' => '2,input', 'templet' => '#sort_sort', 'width' => 120])
            ->addColumn(['field' => 'create_time', 'title' => '创建时间'])
            ->addColumn(['field' => 'update_time', 'title' => '更新时间'])
            ->addColumn(['fixed' => 'right', 'title' => '操作', 'align' => 'center', 'toolbar' => '#barDemo', 'width' => 200])
            ->addRightButtons(['edit' => ['size' => '1000,1000'], 'delete'])
            ->addTopButtons(['add' => ['size' => '1000,1000'], 'deleteAll'])
            ->addSearch([
                ['title', '文章标题搜索', 'input', '', '', '', 'like']
            ])
            ->addSortTool([['name' => 'sort', 'pk' => $this->pk, 'url' => url('update')->build()]])
            ->fetch();
    }
    public function add($tpl = 'productfull/edit')
    {   $list=$this->productModel::where(['is_del'=>0])->order('sort asc')->select();
        View::assign('list', $list);
        View::assign('chekid', []);
        return View::fetch($tpl);
    }

    public function edit($id = '', $tpl = 'productfull/edit', $info = '')
    {
        $info = $this->model::find($id);
        $list=$this->productModel::where(['is_del'=>0])->order('sort asc')->select();
        $chekid=explode(',',$info['product_ids']);
        View::assign('chekid', $chekid);
        View::assign('list', $list);
        return parent::edit($id, $tpl, $info);
    }
    public function savepsot()
    {
        return json($this->model::savepsot($this->request->post())); // TODO: Change the autogenerated stub
    }
}
